package com.trace.demo.repository;

import com.trace.demo.entity.Dealer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Repository
public interface DealerRepository extends JpaRepository<Dealer, Long> {
    
    List<Dealer> findByUserId(Long userId);
    
    @Query("SELECT COUNT(d) FROM Dealer d")
    Long countDealers();
    
    @Query("SELECT COUNT(d) FROM Dealer d WHERE d.createdAt >= ?1")
    Long countTodayNewDealers(LocalDateTime startOfDay);
    
    @Query("SELECT d.province as province, COUNT(d) as count FROM Dealer d GROUP BY d.province")
    List<Map<String, Object>> countDealersByProvince();
} 